<!DOCTYPE html>
<html lang="zh-Hans-CN">
<head>
  <% include("/include/header3.html",{"title":""}){} %>
</head>
<body>

<div id="app">
  <div class="mainBox ">
    <div class="main-container layui-card">
      <div class="layui-card-body">

        <t-form ref="formRef" :data="form" :rules="rules" :disabled="loading" :disabled="loading" scroll-to-first-error="smooth" colon requiredMark>
          <t-row :gutter="[50,20]">
            <t-col :xs="12" :sm="6">
              <t-form-item label="姓名" help="这是一段帮助文字" name="name">
                <t-input v-model="form.name" placeholder="请输入内容"/>
              </t-form-item>
            </t-col>
            <t-col :xs="12" :sm="6">
              <t-form-item label="手机号码" name="tel">
                <t-input placeholder="请输入内容"/>
              </t-form-item>
            </t-col>
            <t-col :xs="12" :sm="6">
              <t-form-item label="手机号码" name="tel">
                <t-input placeholder="请输入内容"/>
              </t-form-item>
            </t-col>
          </t-row>

        </t-form>
      </div>
    </div>
  </div>
  <div class="bottom">
    <t-space class="button-container">
      <t-button :loading="loading" theme="primary" @click="onSave"><i class="layui-icon layui-icon-ok mr-5 text-size-14"></i> 保存</t-button>
      <t-button theme="warning" @click="closeBtn.close"><i class="layui-icon mr-5 text-size-14" :class="closeBtn.i"></i> {{closeBtn.t}}</t-button>
    </t-space>
  </div>
</div>

<script>
  const PATH_URL = "";
</script>

<script>
  setupVue("#app", {
    setup() {
      // 表单相关
      const loading = Vue.ref(true);
      const formRef = Vue.ref(null);
      // 表单数据
      const form = Vue.ref({
        name: undefined,
      });
      const rules = {
        name: [$required('请输入人员名称')]
      };
      console.log(rules);
      // 获取表单数据
      const getForm = (id) => req(axiosGet, PATH_URL + "detail", {id}, (res) => {
        if (res.code === 200) {
          form.value = res.data;
        } else {
          $baseAlert(res.msg, () => closeLayer());
        }
      }, loading);
      const LyData = getLayerData();
      if (LyData && LyData.id) getForm(LyData.id);
      else {

      }

      // 点击保存
      const onSave = () => {
        formRef.value.validate().then((validateResult) => {
          if (validateResult && Object.keys(validateResult).length) {
            const firstError = Object.values(validateResult)[0]?.[0]?.message;
            $baseMsg(firstError);
          } else {
            let REQ;
            let URL;
            if (form.value.id) {
              REQ = axiosPut, URL = PATH_URL + "edit";
            } else {
              REQ = axiosPost, URL = PATH_URL + "add";
            }
            req(REQ, URL, form, (res) => {
              $baseAlert(res.msg, () => {
                if (res.code === 200) closeLayer(parent.reloadData);
              })
            }, loading);
          }
        });
      }

      // 关闭方法
      const closeBtn = useCloseBtn();
      return {
        formRef, loading, form, rules, closeBtn,
        onSave,
      }

    }
  });
</script>


</body>
</html>
